<template>
  <div v-if="$store.state.navFlag">
    <div class="head_top">
      <h1>进思学员管理系统</h1>
      <div>
        <el-link icon="el-icon-edit">做大做强</el-link>
        <el-link icon="el-icon-lock">再创辉煌</el-link>
        <el-link icon="el-icon-star-on">常见文件</el-link>
        <el-link icon="el-icon-lock"
                 @click="dialogVisible=true">安全中心</el-link>
        <el-link icon="el-icon-question"
                 @click="quit">退出</el-link>
        <el-link>{{userInfo.turename}}</el-link>
        <img class="ator"
             src="../assets/logo.png"
             alt="">
      </div>
    </div>
    <!-- 修改密码弹出层 -->
    <el-dialog title="修改密码"
               :visible.sync="dialogVisible"
               width="40%">
      <el-form>
        <el-form-item label="原密码:">
          <el-input v-model="userPwd"></el-input>
        </el-form-item>
        <el-form-item label="新密码:">
          <el-input v-model="newPwd"></el-input>
        </el-form-item>
        <el-form-item label="确认密码:">
          <el-input v-model="surePwd"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button type="success"
                   @click="edit">确定</el-button>
        <el-button type="primary"
                   @click="dialogVisible=false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { editPassword, quitLogin } from '../api/common'
import { mapState } from 'vuex';
export default {
  name: 'Ljfvue2011Headcom',
  data () {
    return {
      dialogVisible: false,
      userPwd: "",
      surePwd: "",
      newPwd: ""
    };
  },
  mounted () {

  },
  computed: {
    ...mapState(["userInfo"])
  },
  methods: {
    async quit () {
      var res = await quitLogin();
      if (res.data.success) {
        this.$message({
          message: "退出登录成功",
          type: "success"
        })
        this.$router.replace("/login")
      }
    },
    async edit () {
      if (this.newPwd == this.surePwd) {
        var res = await editPassword({ userPwd: this.userPwd, newPwd: this.newPwd })
        if (res.data.success) {
          this.userPwd = "";
          this.newPwd = "";
          this.surePwd = "";
          this.$message({
            message: "修改成功,重新登录。。",
            type: "success"
          })
          this.dialogVisible = false;
          this.$router.replace("/login");
        }
      } else {
        this.$message.error({
          message: "俩次密码不一致",
          duration: 2000
        })
      }
    }
  },
};
</script>

<style lang="less" scoped>
.head_top {
  width: 100%;
  height: 90px;
  background: black;
  color: white;
  display: flex;
  justify-content: space-between;
  padding: 0 40px;
  box-sizing: border-box;
  line-height: 90px;
  .el-link {
    color: white;
    margin-right: 20px;
    font-size: 25px;
  }
  .ator {
    width: 80px;
    height: 80px;
    vertical-align: middle;
  }
}
</style>